package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.req.user.QueryAppUserListReq;
import com.letoken.platform.repo.admin.req.user.QueryLineChartReq;
import com.letoken.platform.repo.admin.res.user.QueryAppUserListRes;
import com.letoken.platform.repo.admin.res.user.QueryLineChartRes;
import com.letoken.platform.repo.admin.res.user.QueryUserCountByDateRes;
import com.letoken.platform.repo.app.po.AppUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * app用户信息表 Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2022-11-14
 */
public interface AppUserMapper extends BaseMapper<AppUser> {

    /**
     *  查询app用户列表
     * @param page page
     * @param req req
     * @return return
     */
    Page<QueryAppUserListRes> queryUserList(@Param("page") Page<QueryAppUserListRes> page, @Param("req") QueryAppUserListReq req);

    QueryUserCountByDateRes selectCountByDate();

    List<QueryLineChartRes> queryUserLineChart(@Param("req") QueryLineChartReq req);

    @Select("select 1 from app_user where id = #{userId} limit 1")
    Integer userExists(@Param("userId") Integer userId);

    @Select("select user_name ,head_portrait from app_user where id = #{userId} limit 1")
    AppUser selectSimpleUser(@Param("userId") Integer userId);



    @Select("select create_time from app_user where id = #{userId} limit 1")
    LocalDateTime getRegisterTime(@Param("userId") Integer userId);

    @Select("")
    AppUser videoHomepageInfo(@Param("userId") Integer userId);

    @Update("update app_user set video_follows_count = video_follows_count + #{count} where id = #{userId}")
    void videoFollowsCount(@Param("userId") int userId, @Param("count") int count);

    @Update("update app_user set video_fans_count = video_fans_count + #{count} where id = #{userId}")
    void videoFansCount(@Param("userId") int userId, @Param("count") int count);

    @Update("update app_user set video_likes_count = video_likes_count + #{count} where id = #{userId}")
    void videoLikesCount(@Param("userId") int userId, @Param("count") int count);

    @Select("select id from app_user where id = #{id} for update")
    Integer selectForUpdate(Integer id);
}
